package com.zhaonongzi.tms.util;

import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;

/**
 * Created by wang'ao on 2016/10/14 0014.
 */
public class ExcelUtils {
    /**
     * Creates a cell and aligns it a certain way.
     *
     * @param wb     the workbook
     */
    public static void createCell(Workbook wb, Cell cell, short halign, short valign,Font font) {
        CellStyle cellStyle = wb.createCellStyle();
        cellStyle.setFillBackgroundColor(HSSFColor.AQUA.index);
        cellStyle.setAlignment(halign);
        cellStyle.setVerticalAlignment(valign);
        cellStyle.setFont(font);
        cell.setCellStyle(cellStyle);
    }

    /**
     * 创建一个普通格子
     * @param sheet
     * @param rowIndex
     * @param colIndex
     * @param txt
     */
    public static void createCell(Sheet sheet,int rowIndex,int colIndex,String txt) {
        Row row = sheet.createRow((short) rowIndex);
        Cell cell = row.createCell((short) colIndex);
        cell.setCellValue(txt);
    }
}
